// -------------------------
// 内容工具栏 Toolbar
// -------------------------
// 内容工具栏按钮
var mainToolbarItems = [
    ['img_text', 'new.png', 'listMeeting()', '返回会议管理'],
    ['separator', 'separator_blank.png', '', '']
    //['separator', toolbarImgRelateLoc + 'separator.png', '', '']
];
// 靠右边的工具栏按钮
var rightToolbarItems = [
    //['img_only', 'print.png', 'print()', ''],
    //['separator', 'separator_blank.png', '', ''],
    ['img_only', 'help.gif', 'help()', '']
];
function listMeeting() {
    window.location.href="pageRes?s=htmlContentAction&file_path=oa/assistant/meeting.html";
}


////////////////////////////////////////////////////////////////////////////////
// -------------------------
// 会议室相关内容
// -------------------------
var meetingRoom = {
    panelId: "meetingRoomPanel",
    grid: new SysGrid(),
    gridName: "meetingRoom.grid",
    gridId: "meeting_room_grid",
    // 会议室 Panel
    // 会议室 Panel 工具按钮
    toolbarItems: [
        ['img_only', 'new.png', 'meetingRoomEditorUI()', ''],
        ['separator', 'separator_blank.png', '', ''],
        ['img_only', 'arrow_refresh_small.png', 'xsysGridRefresh(meetingRoom.grid)', '']
    ],
    // 会议室 Panel 标题
    titleItems: [
        ['img_text', 'bullet_arrow_down.png', 'setShowHide()', '会议室列表']
    ]
};
// 会议室列表对象
// 初始化会议室列表函数
function meetingRoomInit(width_, height_) {
    $("#" + meetingRoom.panelId + "_content").html(
    "<div id='" + meetingRoom.gridId + "'/>");
    var header = [
        {align:'center', label:'ID', width:30, type:'checkbox'},
        {align:'left', label:'名称', width:150, type:'script', script:'editMeetingRoom'},
        {align:'left', label:'地址', width:200},
        {align:'left', label:'大小', width:70},
        {align:'left', label:'人数', width:50},
        {align:'left', label:'描述'},
        {align:'left', label:'形状', width:0},
        {align:'left', label:'地图', width:0},
        {align:'left', label:'创建时间', width: 0},
        {align:'left', label:'修改时间', width: 0}
    ];
    var tbConfig = {
        url: 'stringRes?s=coreBaseManagerServletAction&a=list&i=MeetingRoomModel', 
        imgRelateLoc: 'style/powerhua/platform/systable/default_skin/images/', 
        width: width_, height: height_};
    meetingRoom.grid.init(meetingRoom.gridName,
    meetingRoom.gridId, header, tbConfig);

    $.get(meetingRoom.grid.dataUrl, {}, function(result) {
        meetingRoom.grid.ajaxCall(result);
    });
}


////////////////////////////////////////////////////////////////////////////////
// -------------------------
// 会议室编辑相关内容
// -------------------------
var meetingRoomEditorPanel = {
    panelId: "meetingRoomEditorPanel",
    toolbarItems: [
        ['img_only', 'save.png', 'saveMeetingRoom()', '保存'],
        ['separator', 'separator_blank.png', '', ''],
        ['img_only', 'table.png', 'listMeetingRoomUI()', '']
    ],
    // 会议 Panel 标题
    titleItems: [
        ['img_text', 'bullet_arrow_down.png', 'setShowHide()', '编辑会议室信息']
    ],
    eidtorAction: "save", // 会议室保存动作是 save 还是 update
    //
    editorUrl: 'stringRes?s=htmlBodyContentAction&file_path=oa/assistant/meetingroom_editor.html'
};
function meetingRoomEditorInit() {
    $("#" + meetingRoomEditorPanel.panelId + "_content").html(
    "<div id='meetingRoomEditor'/>");
    $.get(meetingRoomEditorPanel.editorUrl, {}, function(result) {
        $("#meetingRoomEditor").html(result);
        $("#MREditorForm").submit(function() {
            $(this).ajaxSubmit({
                url: "stringRes?s=coreBaseManagerServletAction&i=MeetingRoomModel&a=" + meetingRoomEditorPanel.editorAction,
                type: "post",
                success: function() {
                    alert("success");
                } 
            });
            return false;
        });
    });
}



////////////////////////////////////////////////////////////////////////////////
// -------------------------
// Action 
// -------------------------
function listMeetingRoomUI() {
    $("#" + meetingRoom.panelId).css("display", "block");
    $("#" + meetingRoomEditorPanel.panelId).css("display", "none");
}
// 点击工具栏上的增加会议室时的动作
// 增加会议室
function meetingRoomEditorUI() {
    $("#" + meetingRoom.panelId).css("display", "none");
    $("#" + meetingRoomEditorPanel.panelId).css("display", "block");
    setFormFieldNullValue("MREditorForm");
}
function addMeetingRoom() {
    meetingRoomEditorUI();
    // 保存动作是 save
    meetingRoomEditorPanel.editorAction = "save";
}
function editMeetingRoom(gridObj, rowNum) {
    meetingRoomEditorUI();
    // 保存动作是 update
    meetingRoomEditorPanel.editorAction = "update";
    $.get('stringRes?s=coreBaseManagerServletAction&i=MeetingRoomModel&a=getObjectById', {
        id_: gridObj.bodyData[rowNum][0]
    }, function(result) {
        var fields = eval(result);
        setFormFieldValue('MREditorForm', fields);
    });
}
function saveMeetingRoom() {
    $("#MREditorForm").submit();
}
// 点击工具栏上的删除按钮时的动作
// 删除会议室
function deleteMeetingRoom() {
    alert("delete meeting room");
}